<template>
  <div class="mobile-container">
    <div class="mobile-content">
      <!-- 页面内容区域 -->
      <div class="page-container">
        <transition name="el-fade-in ">
          <keep-alive>
            <router-view/>
          </keep-alive>
        </transition>
      </div>

      <!-- 底部导航栏 -->
      <div class="bottom-nav">
        <router-link
          v-for="(item, index) in navItems"
          :key="index"
          :to="item.path"
          active-class="active"
          class="nav-item">
          <svg-icon :class="{'active':$route.path === item.path}" :icon-class="item.meta.icon" class="nav-icon"/>
          <span>{{ item.meta.title }}</span>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
import {ordinaryRoute} from '@/router'

export default {
  name: 'MobileLayout',
  created() {
    // 监听路由变化，并更新底部导航栏
  },
  data() {
    return {
      navItems: ordinaryRoute.children.filter(item => item.nav)
    }
  }
}
</script>

<style scoped>
/* 移动端容器样式 */
.mobile-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background-color: #f5f5f5;
  padding: 0;
}

.mobile-content {
  width: 100%;
  min-width: 400px;
  max-width: 768px;
  height: 100vh;
  background-color: #fff;
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
}

/* 页面容器样式 */
.page-container {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 50px; /* 为底部导航栏留出空间 */
}

/* 底部导航栏样式 - 类似小程序风格 */
.bottom-nav {
  display: flex;
  font-family: serif;
  justify-content: space-around;
  align-items: center;
  height: 50px;
  background-color: #fff;
  border-top: 1px solid #f0f0f0;
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 768px;
  min-width: 400px;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  height: 100%;
  color: #8a8a8a;
  text-decoration: none;
  transition: color 0.2s;
  text-align: center;
  padding: 5px 0;
}

.nav-item.active {
  color: #0078D4; /* 微信小程序绿色 */
}

.nav-icon {
  font-size: 20px;
  display: block;
  line-height: 1;
  margin: 0 0 2px 0 !important;
}

.nav-item span {
  font-size: 10px;
  display: block;
  line-height: 1;
  margin-top: 2px;
}

/* 响应式调整 */
@media (max-width: 400px) {
  .mobile-content, .bottom-nav {
    min-width: 100%;
  }
}

@media (min-width: 769px) {
  .mobile-container {
    background-color: #f5f5f5;
  }

  .mobile-content {
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
  }
}
</style>
